package com.xhwl.data.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.xhwl.common.dto.cent.sdata.OrgNodeDTO;
import com.xhwl.common.dto.cent.sdata.OrganizationDTO;
import com.xhwl.common.enums.OrganizationTypeEnum;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.sdata.Account;
import com.xhwl.common.pojo.cent.sdata.Industry;
import com.xhwl.common.pojo.cent.sdata.Organization;
import com.xhwl.common.pojo.cent.sdata.Project;
import com.xhwl.common.query.cent.sdata.OrganizationQuery;
import com.xhwl.common.query.cent.sdata.SpaceQuery;
import com.xhwl.data.pojo.dto.personal.OrgStaffTreeDTO;
import com.xhwl.data.pojo.dto.personal.OrgStaffTreeQueryDTO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @description: 组织管理
 * @author: lianghz
 * @create: 2020-11-25
 **/
@RestController
public interface IOrganizationService extends IService<Organization> {

    /**
     * 根据组织id查找子组织id集合
     */
    @RequestMapping(value = "/organization-service/getOrgIdsList", method = RequestMethod.POST)
    List<Integer> getOrgIdsList(@RequestPart("orgIds") List<Integer> orgIds);

    /**
     * 是否能选择相关的组织架构
     *
     * @param account
     * @param organizationId
     * @return
     */

    Boolean canSelect(Account account, Integer organizationId);

    /**
     * 通过主键id查找 组织
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/organization-service/get-by-id", method = RequestMethod.POST)
    Organization getById(@RequestParam Integer id);

    /**
     * 获取指定类型空间数据（与账号无关）
     *
     * @param orgNodeDTO
     * @return
     */
    List<Organization> nodeListByType(OrgNodeDTO orgNodeDTO);

    /**
     * 创建组织
     *
     * @param organization
     * @return
     */
    @RequestMapping(value = "/organization-service/create", method = RequestMethod.POST)
    ResultJson create(@RequestPart Organization organization);

    /**
     * 批量创建组织
     *
     * @param organizationList
     * @return
     */
    @RequestMapping(value = "/organization-service/batch-create", method = RequestMethod.POST)
    ResultJson create(@RequestPart List<Organization> organizationList);

    /**
     * 批量导入组织
     */

    @RequestMapping(value = "/organization-service/batch-import",method = RequestMethod.POST)
    ResultJson createByImport(@RequestPart("file") MultipartFile file,@RequestPart Short industryId,@RequestPart Integer enterpriseId,Account account);

    /**
     * 批量导出错误数据
     */
    @RequestMapping(value = "/organization-service/export-error",method = RequestMethod.POST)
    void exportErrorByFileId(HttpServletResponse response, @RequestParam String fileId);

    /**
     * 批量导出组织
     */
    @RequestMapping(value = "/organization-service/batch-export",method = RequestMethod.POST)
    void exportBatchOrg(@RequestParam String keywords,@RequestParam Integer enterpriseId,HttpServletResponse response);

    /**
     * 导出组织模板
     */
    @GetMapping(value = "/organization/template-export")
    void  exportOrganizationTemp(Integer enterpriseId,HttpServletResponse response)throws IOException;


    /**
     * 删除组织 (有子节点不能删除)
     *
     * @param id
     * @param account
     * @return
     */
    @RequestMapping(value = "/organization-service/delete", method = RequestMethod.POST)
    ResultJson delete(@RequestParam Integer id, @RequestPart(required = false) Account account);

    /**
     * 删除节点,包含子节点
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/organization-service/delete-follow", method = RequestMethod.POST)
    ResultJson deleteFollow(@RequestParam Integer id);

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @RequestMapping(value = "/organization-service/batch-delete", method = RequestMethod.POST)
    ResultJson batchDelete(@RequestPart List<Integer> ids);

    /**
     * 修改组织
     *
     * @param organization
     * @return
     */
    @RequestMapping(value = "/organization-service/update", method = RequestMethod.POST)
    ResultJson update(@RequestPart Organization organization);

    @RequestMapping(value = "/organization-service/update/v2", method = RequestMethod.POST)
    ResultJson update2(@RequestPart OrganizationDTO organizationDTO);

    /**
     * 查询组织树
     *
     * @param organizationQuery
     * @return
     */
    @RequestMapping(value = "/organization-service/tree", method = RequestMethod.POST)
    List<OrganizationDTO> tree(@RequestPart OrganizationQuery organizationQuery);

    /**
     * 通过项目id查询组织分页查询
     *type(6:房间)
     */
    @RequestMapping(value = "/organization-service/orgPage", method = RequestMethod.POST)
    Page<Organization> orgPage(@RequestPart List<Integer> projectIds,@RequestPart Page page,@RequestPart List<Integer> types);

    /**
     * 查询组织树 组织结点有负责人
     *
     * @param organizationQuery
     * @return
     */
    List<OrganizationDTO> treeWithManager(OrganizationQuery organizationQuery);

    /**
     * 根据房间状态获取树
     */
    List<OrganizationDTO> treeCp(OrganizationQuery organizationQuery);

    /**
     * 查询组织列表
     *
     * @param organizationQuery
     * @return
     */
    @RequestMapping(value = "/organization-service/list", method = RequestMethod.POST)
    List<Organization> list(@RequestPart(required = false) OrganizationQuery organizationQuery);

    /**
     * 根据链式名称查询组织
     *
     * @param organizationQuery
     * @return
     */
    @RequestMapping(value = "/organization-service/list-by-chainname", method = RequestMethod.POST)
    Map<String, Organization> listByChainName(@RequestPart(required = false) OrganizationQuery organizationQuery);

    /**
     * 查找单个组织
     *
     * @param organizationQuery
     * @return
     */
    @RequestMapping(value = "/organization-service/find", method = RequestMethod.POST)
    Organization find(@RequestPart(required = false) OrganizationQuery organizationQuery);

    /**
     * 根据组织id链式拼接完整名称
     *
     * @param organizationQuery
     * @return
     */
    @RequestMapping(value = "/organization-service/full-name", method = RequestMethod.POST)
    String fullName(@RequestPart OrganizationQuery organizationQuery);

    @RequestMapping(value = "/organization-service/full-code", method = RequestMethod.POST)
    String fullCode(@RequestPart OrganizationQuery organizationQuery);

    @RequestMapping(value = "/organization-service/batch-full-code", method = RequestMethod.POST)
    Map<Integer, String> batchFullCode(@RequestPart OrganizationQuery organizationQuery);

    @RequestMapping(value = "/organization-service/batch-full-code-v2", method = RequestMethod.POST)
    List<Organization> batchFullCodeV2(@RequestPart OrganizationQuery organizationQuery);

    /**
     * 根据组织id链式拼接完整名称
     *
     * @param organizationQuery
     * @return
     */
    @RequestMapping(value = "/organization-service/batch-full-name", method = RequestMethod.POST)
    Map<Integer, String> batchFullName(@RequestPart OrganizationQuery organizationQuery);

    /**
     * 项目选择树
     *
     * @param query
     * @return
     */
    List<OrganizationDTO> projectChose(OrganizationQuery query);

    /**
     * 是否有子结点
     *
     * @param id
     * @return
     */
    Boolean hasChild(Integer id);

    /**
     * 获取当前id下的所有子节点 返回值包含当前节点
     *
     * @return
     */
    @RequestMapping(value = "/organization-service/child", method = RequestMethod.POST)
    List<Organization> child(@RequestPart OrganizationQuery query);

    /**
     * 超级管理员或者管理者角色查询项目选择器
     *
     * @param query
     * @return
     */
    List<OrganizationDTO> adminProjectChose(OrganizationQuery query);

    /**
     * 根据项目查询组织架构
     *
     * @param organizationQuery
     * @return
     * @deprecated 被 batchFullName 方法代替
     */
    @Deprecated
    Map<Integer, List<Organization>> findDefault(OrganizationQuery organizationQuery);

    /**
     * 组织分页查询
     *
     * @param organizationQuery
     * @param page
     * @return
     */
    Page<Organization> page(OrganizationQuery organizationQuery, Page page);

    /**
     * 项目选择器，展示树结构的内容为企业和企业下的项目
     *
     * @param query
     * @return
     */
    @RequestMapping(value = "/organization-service/project-chose/v2", method = RequestMethod.POST)
    List<OrganizationDTO> projectChoseV2(@RequestPart OrganizationQuery query);

    @RequestMapping(value = "/organization-service/project-chose/v3", method = RequestMethod.POST)
    List<Project> projectChoseV3(@RequestPart OrganizationQuery query, @RequestPart(required = false) Account account);

    /**
     * 根据业态信息查询组织类型 (空间类型)
     *
     * @param industryId
     * @return
     */
    @RequestMapping(value = "/organization-service/type", method = RequestMethod.POST)
    List<OrganizationTypeEnum> type(@RequestPart Short industryId);

    /**
     * 组织树查询 通讯录用
     *
     * @param organizationQuery
     * @return
     */
    @Deprecated
    List<OrganizationDTO> contactTree(OrganizationQuery organizationQuery);

    /**
     * 组织列表查询 通讯录用
     *
     * @param organizationQuery
     * @return
     */
    List<Organization> contactList(OrganizationQuery organizationQuery);

    /**
     * 编辑组织 企业通讯录异步生成树
     *
     * @param orgStaffTreeQueryDTO
     * @return
     */
    List<OrgStaffTreeDTO> editTree(OrgStaffTreeQueryDTO orgStaffTreeQueryDTO);

    /**
     * 编辑组织 异步树生成 不过滤可见性
     *
     * @param orgStaffTreeQueryDTO
     * @return
     */
    List<OrgStaffTreeDTO> editTreeNoVisiable(OrgStaffTreeQueryDTO orgStaffTreeQueryDTO);

    OrganizationDTO detail(Integer id);

    @RequestMapping(value = "/organization-service/detail-by-code-and-type", method = RequestMethod.POST)
    Organization detailByCodeAndType(@RequestParam("code") String code, @RequestParam("type") Integer type);

    /**
     * 检查编码是否唯一
     *
     * @param dto
     * @return
     */
    ResultJson checkUniqueCode(OrganizationDTO dto);

    List<OrganizationDTO> listV2(OrganizationQuery query);

    ResultJson allToTree(OrgStaffTreeQueryDTO orgStaffTreeQueryDTO);

    List<OrganizationDTO> getOrgByEntId();

    List<OrganizationDTO> allSpace();

    /**
     * 根据房间查找楼栋
     */
    @RequestMapping(value = "/organization-service/get-parent", method = RequestMethod.POST)
    Map<Integer,List<Organization>> getParent(@RequestPart OrganizationQuery query);

    /**
     * 根据项目查询父子级 举个例子：楼栋下所有房间
     * @param query 传参项目+类型
     * @return
     */
    @RequestMapping(value = "/organization-service/child-by-project", method = RequestMethod.POST)
    Map<Integer,List<Organization>> findChildByProject(@RequestPart OrganizationQuery query);

    ResultJson refreshSort(OrganizationQuery organizationQuery);
}